/*
 * JSONUtil.java
 * Copyright 2012 Erik Strelzoff
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.magelord.utils;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;

import java.util.Arrays;
import java.util.Random;

public class JSONUtil {
	
	public static Gson getGson() {
		// Build our Gson instance.
		// TBI:  Load options from a gson config file?
		GsonBuilder gsonBuilder = new GsonBuilder();
		// Use pretty printing during development/debugging.
		gsonBuilder.setPrettyPrinting();
		return gsonBuilder.create();
	}
	
	public static void main(String[] args) {
		String[][] map = makeRandomMap(8,16);
		
		for (String[] column : map) {
			System.out.println(Arrays.toString(column));
		}
		
		System.out.println("********");
		Gson gson = new Gson();
		String json = gson.toJson(map);
		System.out.println(json);
	}
	
	public static String[][] makeRandomMap(int rows, int cols) {
		String[][] result = new String[cols][];
		Random random = new Random();
		for (int c = 0; c < cols; c++) {
			String[] row = new String[rows];
			for (int r = 0; r < rows; r++) {
				String hex;
				int ran = random.nextInt(16);
				
				switch (ran) {
					case 0:
					
						hex = "desert";
						break;
					case 3:
					case 4:
					case 6:
					
						hex = "water";
						break;
					case 5:
						hex = "mountain";
						break;
					case 1:
					case 2:
					case 7:
					case 8:
					case 9:
					case 10:
					case 11:
					case 12:
						hex = "forest";
						break;
					default:
						hex = "forest";
						break;
				}

				row[r] = hex;
			}
			result[c] = row;
		}
		return result;
	}
	
}
